﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" Inherits="System.Web.Mvc.ViewPage<QuanLyNhaThuoc.Models.ExportModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div class="box box-success">
        <div class="box-header">
            <h3 class="box-title">
                Danh sách phiếu xuất hàng
            </h3>
            <div class="box-tools">
                <div class="row">
                    <div class="col-md-12">
                        <div class="col-md-8 xl1">
                            <div class="btn-toolbar">
                                <button onclick="location.href = '/Transaction/Sale'" class="btn btn-default btn-sm">
                                    Bán hàng
                                </button>
                                <button id="Fix_Bill" class="btn btn-default btn-sm">
                                    Sửa phiếu</button>
                                <button id="Remove_Bill" class="btn btn-default btn-sm">
                                    Hủy phiếu</button>
                            </div>
                        </div>
                        <div class="col-md-4 xl2">
                            <% using (Html.BeginForm("SearchBill", "Transaction", FormMethod.Post)) { %>
                            <div class="input-group">
                                <div class="input-group-btn remove-width">
                                    <%: Html.DropDownListFor(m => m.KeySearch, Model.ListKeySearch, new { @class = "select-default" })%>
                                </div>
                                <%: Html.TextBoxFor(m => m.ValueSearch, new { @class = "form-control", @placeholder = "Tìm kiếm" }) %>
                                <div class="input-group-addon">
                                    <input type="submit" class="btn-f" value />
                                    <i class="fa fa-search"></i>
                                </div>
                            </div>
                            <%} %>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <form id="form">
        <div class="box-body no-padding table-responsive">
            <table id="list" class="table table-hover" cellpadding="0" cellspacing="0" border="0">
                <tbody>
                    <tr class="trfc">
                        <th align="center">
                            <input type="checkbox" id="checkAll" />
                        </th>
                        <th>
                            #
                        </th>
                        <th>
                            Số phiếu
                        </th>
                        <th>
                            Ngày nhập
                        </th>
                        <th>
                            Người nhập
                        </th>
                        <th>
                            Tổng sản phẩm
                        </th>
                        <th>
                            Tổng giá trị
                        </th>
                        <th>
                            Diễn giải
                        </th>
                    </tr>
                    <% if (Model.ListExportBill.Count() != 0) { %>
                    <% foreach (var item in Model.ListExportBill) { %>
                    <tr>
                        <td align="center">
                            <input type="checkbox" id="maxcheck<%: item.ID %>" value="<%: item.EBID %>" />
                        </td>
                        <td align="center">
                            <%: item.ID%>
                        </td>
                        <td>
                            <%: item.EBNumber %>
                        </td>
                        <td align="center">
                            <%: item.DateCreated %>
                        </td>
                        <td>
                            <%: item.UserCreated %>
                        </td>
                        <td align="center">
                            <%= QuanLyNhaThuoc.HelperClass.Common.FormatMoneyDisplay((item.Count == null ? "0" : item.Count.ToString()), item.CCYID) %>
                        </td>
                        <td align="right">
                            <%= QuanLyNhaThuoc.HelperClass.Common.FormatMoneyDisplay((item.OverallWorth == null ? "0" : item.OverallWorth.ToString()), item.CCYID)%>&nbsp;
                            <%: item.Content %>
                        </td>
                        <td>
                            <%: item.Description %>
                        </td>
                    </tr>
                    <% } %>
                    <% } %>
                    <% else { %>
                    <tr>
                        <td colspan="8">
                            <%: ConfigurationManager.AppSettings["NoRecord"].ToString()%>
                        </td>
                    </tr>
                    <% } %>
                </tbody>
            </table>
        </div>
        <% if (Model.ListExportBill.Count() != 0) { %>
        <div class="col-xs-6 pad">
            <div class="dataTables_info">
                <b>Có tất cả
                    <%: Model.paging.TotalRecordCount%>
                    sản phẩm tìm thấy</b></div>
        </div>
        <div class="col-xs-6">
            <div class="dataTables_paginate pagination-sm pull-right">
                <% Html.RenderPartial("Pager", Model.paging); %>
            </div>
        </div>
        <%} %>
        </form>
    </div>
    <script src="/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
    <script src="/Scripts/Pharma/jquery.min.js" type="text/javascript"></script>
    <!-- jQuery UI 1.10.3 -->
    <script src="/Scripts/Pharma/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
    <!-- Bootstrap -->
    <script src="/Scripts/Pharma/bootstrap.min.js" type="text/javascript"></script>
    <!-- Bootstrap WYSIHTML5 -->
    <script src="/Scripts/Pharma/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"
        type="text/javascript"></script>
    <!-- Notification -->
    <script src="/Scripts/Pharma/plugins/notification/jquery.noty.packaged.min.js" type="text/javascript"></script>
    <script src="/Scripts/Pharma/plugins/notification/Notification.js" type="text/javascript"></script>
    <!-- AdminLTE App -->
    <script src="/Scripts/Pharma/AdminLTE/app_permission.js" type="text/javascript"></script>
    <script src="/Scripts/Pharma/plugins/Combogrid/jquery-ui-1.10.1.custom.min.js" type="text/javascript"></script>
    <link href="/Content/themes/Pharma/smoothness/jquery-ui-1.10.1.custom.css" rel="stylesheet"
        type="text/css" />
    <!-- Validation engine -->
    <link href="/Content/themes/ValidationEngine/validationEngine.jquery.css" rel="stylesheet"
        type="text/css" />
    <script src="/Scripts/Pharma/plugins/ValidationEngine/jquery.validationEngine.js"
        type="text/javascript"></script>
    <script src="/Scripts/Pharma/plugins/ValidationEngine/jquery.validationEngine-vi.js"
        type="text/javascript"></script>
    <script src="/Scripts/Pharma/Pharmacy.js" type="text/javascript"></script>
    <script type="text/javascript">
        Pharma._init();
        Pharma._addActive(["tvTransaction", "liSale"], "ulTransaction");
        Pharma._checkAll("checkAll");
        Pharma._boundCheckBox();

        $("#Fix_Bill").click(function (e) {
            e.preventDefault();
            Pharma._checkboxCheck($("#list input:checkbox:not(#checkAll):checked").length, "/Transaction/Fix_Bill/");
        });

        $("#Remove_Bill").click(function (e) {
            e.preventDefault();
            if ($("#list input:checkbox:not(#checkAll):checked").length > 0) {
                var checkboxArr = [];
                $("#list input:checkbox:not(#checkAll):checked").each(function (i, v) {
                    checkboxArr.push($(v).val());
                });

                var n = noty({ layout: 'center', text: 'Bạn có chắc chắn hủy phiếu này không?', buttons: [
                        { addClass: 'btn btn-primary', text: 'Có', onClick: function ($noty) {
                            $noty.close();
                            $.ajax({
                                type: 'POST',
                                url: '/Transaction/DeleteExportBill',
                                data: JSON.stringify({ ls_EBID: checkboxArr }),
                                dataType: 'json',
                                contentType: 'application/json; charset=utf-8',
                                async: false,
                                success: function (rs) {
                                    switch (rs.status) {
                                        case 0:
                                            $("#list tbody").find("tr:gt(0)").remove();
                                            for (var i = 0; i < rs.data.length; i++) {
                                                $("#list tbody").append('<tr><td align="center"><input id type="checkbox" value="' + rs.data[i].EBID + '" /></td><td align="center">' + rs.data[i].ID + '.</td><td style="white-space: normal">' + rs.data[i].EBNumber + '</td><td>' + rs.data[i].DateCreated + '</td><td align="center">' + rs.data[i].UserCreated + '</td><td align="center">' + rs.data[i].Count + '</td><td align="center">' + rs.data[i].OverallWorth + '</td><td align="center">' + (rs.data[i].Description == null ? "" : rs.data[i].Description) + '</td></tr>').slideDown('slow');
                                            }
                                            Pharma._scroll("list", 250);
                                            $('html').animate({ scrollTop: $(document).height() }, 1000);
                                            var n = noty({ layout: 'topRight', text: 'Bạn đã xóa phiếu nhập thành công', type: 'success', timeout: 2000 });
                                            break;
                                        case 1:
                                            var n = noty({ layout: 'topRight', text: 'Có lỗi xảy ra', type: 'error', timeout: 2000 });
                                            break;
                                    }
                                },
                                error: function (rs) {
                                    var n = noty({ layout: 'topRight', text: 'Có lỗi xảy ra', type: 'error', timeout: 2000 });
                                    return false;
                                },
                                traditional: true
                            });
                        }
                        },
                        { addClass: 'btn btn-danger', text: 'Không', onClick: function ($noty) {
                            $noty.close();
                        }
                        }
                    ]
                });
            }
            else {
                jQuery($("#list input:checkbox:not(#checkAll):first")).validationEngine('showPrompt', '* Vui lòng chọn một tùy chọn', 'error').focus();
                return false;
            }
        });        

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
    <%:ViewBag.Title %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="NavBar" runat="server">
    <h1>
        Bán hàng <small>Control panel</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>Home</a></li>
        <li class="active">Giao dịch</li>
        <li class="active">Bán hàng</li>
    </ol>
</asp:Content>
